using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace sharpTV.Entities
{
	/// <summary>
	/// Strongly-typed collection for the Channel class.
	/// </summary>
    [Serializable]
	public partial class ChannelCollection : ActiveList<Channel, ChannelCollection>
	{	   
		public ChannelCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>ChannelCollection</returns>
		public ChannelCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Channel o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the sharpTV_Channels table.
	/// </summary>
	[Serializable]
	public partial class Channel : ActiveRecord<Channel>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Channel()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Channel(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Channel(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Channel(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sharpTV_Channels", TableType.Table, DataService.GetInstance("sharpTVSubSonicProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarChannelId = new TableSchema.TableColumn(schema);
				colvarChannelId.ColumnName = "ChannelId";
				colvarChannelId.DataType = DbType.Int32;
				colvarChannelId.MaxLength = 0;
				colvarChannelId.AutoIncrement = true;
				colvarChannelId.IsNullable = false;
				colvarChannelId.IsPrimaryKey = true;
				colvarChannelId.IsForeignKey = false;
				colvarChannelId.IsReadOnly = false;
				colvarChannelId.DefaultSetting = @"";
				colvarChannelId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarChannelId);
				
				TableSchema.TableColumn colvarChannelUId = new TableSchema.TableColumn(schema);
				colvarChannelUId.ColumnName = "ChannelUId";
				colvarChannelUId.DataType = DbType.Guid;
				colvarChannelUId.MaxLength = 0;
				colvarChannelUId.AutoIncrement = false;
				colvarChannelUId.IsNullable = true;
				colvarChannelUId.IsPrimaryKey = false;
				colvarChannelUId.IsForeignKey = false;
				colvarChannelUId.IsReadOnly = false;
				
						colvarChannelUId.DefaultSetting = @"(newid())";
				colvarChannelUId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarChannelUId);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 2000;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				
						colvarTitle.DefaultSetting = @"(N'')";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = 4000;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				
						colvarDescription.DefaultSetting = @"(N'')";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarIsTradeMarked = new TableSchema.TableColumn(schema);
				colvarIsTradeMarked.ColumnName = "IsTradeMarked";
				colvarIsTradeMarked.DataType = DbType.Boolean;
				colvarIsTradeMarked.MaxLength = 0;
				colvarIsTradeMarked.AutoIncrement = false;
				colvarIsTradeMarked.IsNullable = true;
				colvarIsTradeMarked.IsPrimaryKey = false;
				colvarIsTradeMarked.IsForeignKey = false;
				colvarIsTradeMarked.IsReadOnly = false;
				
						colvarIsTradeMarked.DefaultSetting = @"((0))";
				colvarIsTradeMarked.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsTradeMarked);
				
				TableSchema.TableColumn colvarUrl = new TableSchema.TableColumn(schema);
				colvarUrl.ColumnName = "URL";
				colvarUrl.DataType = DbType.String;
				colvarUrl.MaxLength = 256;
				colvarUrl.AutoIncrement = false;
				colvarUrl.IsNullable = true;
				colvarUrl.IsPrimaryKey = false;
				colvarUrl.IsForeignKey = false;
				colvarUrl.IsReadOnly = false;
				
						colvarUrl.DefaultSetting = @"(N'')";
				colvarUrl.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUrl);
				
				TableSchema.TableColumn colvarLogoPositionId = new TableSchema.TableColumn(schema);
				colvarLogoPositionId.ColumnName = "LogoPositionId";
				colvarLogoPositionId.DataType = DbType.Int32;
				colvarLogoPositionId.MaxLength = 0;
				colvarLogoPositionId.AutoIncrement = false;
				colvarLogoPositionId.IsNullable = true;
				colvarLogoPositionId.IsPrimaryKey = false;
				colvarLogoPositionId.IsForeignKey = false;
				colvarLogoPositionId.IsReadOnly = false;
				colvarLogoPositionId.DefaultSetting = @"";
				colvarLogoPositionId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogoPositionId);
				
				TableSchema.TableColumn colvarLogo = new TableSchema.TableColumn(schema);
				colvarLogo.ColumnName = "Logo";
				colvarLogo.DataType = DbType.Guid;
				colvarLogo.MaxLength = 0;
				colvarLogo.AutoIncrement = false;
				colvarLogo.IsNullable = true;
				colvarLogo.IsPrimaryKey = false;
				colvarLogo.IsForeignKey = false;
				colvarLogo.IsReadOnly = false;
				
						colvarLogo.DefaultSetting = @"(N'')";
				colvarLogo.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogo);
				
				TableSchema.TableColumn colvarTimezone = new TableSchema.TableColumn(schema);
				colvarTimezone.ColumnName = "Timezone";
				colvarTimezone.DataType = DbType.Int32;
				colvarTimezone.MaxLength = 0;
				colvarTimezone.AutoIncrement = false;
				colvarTimezone.IsNullable = true;
				colvarTimezone.IsPrimaryKey = false;
				colvarTimezone.IsForeignKey = false;
				colvarTimezone.IsReadOnly = false;
				colvarTimezone.DefaultSetting = @"";
				colvarTimezone.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTimezone);
				
				TableSchema.TableColumn colvarCultureId = new TableSchema.TableColumn(schema);
				colvarCultureId.ColumnName = "CultureId";
				colvarCultureId.DataType = DbType.Int32;
				colvarCultureId.MaxLength = 0;
				colvarCultureId.AutoIncrement = false;
				colvarCultureId.IsNullable = true;
				colvarCultureId.IsPrimaryKey = false;
				colvarCultureId.IsForeignKey = false;
				colvarCultureId.IsReadOnly = false;
				colvarCultureId.DefaultSetting = @"";
				colvarCultureId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCultureId);
				
				TableSchema.TableColumn colvarCreationDate = new TableSchema.TableColumn(schema);
				colvarCreationDate.ColumnName = "CreationDate";
				colvarCreationDate.DataType = DbType.DateTime;
				colvarCreationDate.MaxLength = 0;
				colvarCreationDate.AutoIncrement = false;
				colvarCreationDate.IsNullable = true;
				colvarCreationDate.IsPrimaryKey = false;
				colvarCreationDate.IsForeignKey = false;
				colvarCreationDate.IsReadOnly = false;
				
						colvarCreationDate.DefaultSetting = @"(getdate())";
				colvarCreationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreationDate);
				
				TableSchema.TableColumn colvarOwner = new TableSchema.TableColumn(schema);
				colvarOwner.ColumnName = "Owner";
				colvarOwner.DataType = DbType.Guid;
				colvarOwner.MaxLength = 0;
				colvarOwner.AutoIncrement = false;
				colvarOwner.IsNullable = true;
				colvarOwner.IsPrimaryKey = false;
				colvarOwner.IsForeignKey = false;
				colvarOwner.IsReadOnly = false;
				colvarOwner.DefaultSetting = @"";
				colvarOwner.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOwner);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sharpTVSubSonicProvider"].AddSchema("sharpTV_Channels",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("ChannelId")]
		[Bindable(true)]
		public int ChannelId 
		{
			get { return GetColumnValue<int>(Columns.ChannelId); }
			set { SetColumnValue(Columns.ChannelId, value); }
		}
		  
		[XmlAttribute("ChannelUId")]
		[Bindable(true)]
		public Guid? ChannelUId 
		{
			get { return GetColumnValue<Guid?>(Columns.ChannelUId); }
			set { SetColumnValue(Columns.ChannelUId, value); }
		}
		  
		[XmlAttribute("Title")]
		[Bindable(true)]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }
			set { SetColumnValue(Columns.Title, value); }
		}
		  
		[XmlAttribute("Description")]
		[Bindable(true)]
		public string Description 
		{
			get { return GetColumnValue<string>(Columns.Description); }
			set { SetColumnValue(Columns.Description, value); }
		}
		  
		[XmlAttribute("IsTradeMarked")]
		[Bindable(true)]
		public bool? IsTradeMarked 
		{
			get { return GetColumnValue<bool?>(Columns.IsTradeMarked); }
			set { SetColumnValue(Columns.IsTradeMarked, value); }
		}
		  
		[XmlAttribute("Url")]
		[Bindable(true)]
		public string Url 
		{
			get { return GetColumnValue<string>(Columns.Url); }
			set { SetColumnValue(Columns.Url, value); }
		}
		  
		[XmlAttribute("LogoPositionId")]
		[Bindable(true)]
		public int? LogoPositionId 
		{
			get { return GetColumnValue<int?>(Columns.LogoPositionId); }
			set { SetColumnValue(Columns.LogoPositionId, value); }
		}
		  
		[XmlAttribute("Logo")]
		[Bindable(true)]
		public Guid? Logo 
		{
			get { return GetColumnValue<Guid?>(Columns.Logo); }
			set { SetColumnValue(Columns.Logo, value); }
		}
		  
		[XmlAttribute("Timezone")]
		[Bindable(true)]
		public int? Timezone 
		{
			get { return GetColumnValue<int?>(Columns.Timezone); }
			set { SetColumnValue(Columns.Timezone, value); }
		}
		  
		[XmlAttribute("CultureId")]
		[Bindable(true)]
		public int? CultureId 
		{
			get { return GetColumnValue<int?>(Columns.CultureId); }
			set { SetColumnValue(Columns.CultureId, value); }
		}
		  
		[XmlAttribute("CreationDate")]
		[Bindable(true)]
		public DateTime? CreationDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.CreationDate); }
			set { SetColumnValue(Columns.CreationDate, value); }
		}
		  
		[XmlAttribute("Owner")]
		[Bindable(true)]
		public Guid? Owner 
		{
			get { return GetColumnValue<Guid?>(Columns.Owner); }
			set { SetColumnValue(Columns.Owner, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid? varChannelUId,string varTitle,string varDescription,bool? varIsTradeMarked,string varUrl,int? varLogoPositionId,Guid? varLogo,int? varTimezone,int? varCultureId,DateTime? varCreationDate,Guid? varOwner)
		{
			Channel item = new Channel();
			
			item.ChannelUId = varChannelUId;
			
			item.Title = varTitle;
			
			item.Description = varDescription;
			
			item.IsTradeMarked = varIsTradeMarked;
			
			item.Url = varUrl;
			
			item.LogoPositionId = varLogoPositionId;
			
			item.Logo = varLogo;
			
			item.Timezone = varTimezone;
			
			item.CultureId = varCultureId;
			
			item.CreationDate = varCreationDate;
			
			item.Owner = varOwner;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varChannelId,Guid? varChannelUId,string varTitle,string varDescription,bool? varIsTradeMarked,string varUrl,int? varLogoPositionId,Guid? varLogo,int? varTimezone,int? varCultureId,DateTime? varCreationDate,Guid? varOwner)
		{
			Channel item = new Channel();
			
				item.ChannelId = varChannelId;
			
				item.ChannelUId = varChannelUId;
			
				item.Title = varTitle;
			
				item.Description = varDescription;
			
				item.IsTradeMarked = varIsTradeMarked;
			
				item.Url = varUrl;
			
				item.LogoPositionId = varLogoPositionId;
			
				item.Logo = varLogo;
			
				item.Timezone = varTimezone;
			
				item.CultureId = varCultureId;
			
				item.CreationDate = varCreationDate;
			
				item.Owner = varOwner;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ChannelIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ChannelUIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn DescriptionColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn IsTradeMarkedColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn UrlColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn LogoPositionIdColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn LogoColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn TimezoneColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn CultureIdColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn CreationDateColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn OwnerColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ChannelId = @"ChannelId";
			 public static string ChannelUId = @"ChannelUId";
			 public static string Title = @"Title";
			 public static string Description = @"Description";
			 public static string IsTradeMarked = @"IsTradeMarked";
			 public static string Url = @"URL";
			 public static string LogoPositionId = @"LogoPositionId";
			 public static string Logo = @"Logo";
			 public static string Timezone = @"Timezone";
			 public static string CultureId = @"CultureId";
			 public static string CreationDate = @"CreationDate";
			 public static string Owner = @"Owner";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
